package org.finmanager.core;

import org.finmanager.data.CategoryList;

import javax.swing.*;

/**
 * Created by Kelvin on 1/4/2014.
 */

//For simplicity and saving space, we use COMBOX BOX to list categories
public class CategoryComboBoxModel extends AbstractListModel implements ComboBoxModel{
	private final CategoryList categoryList;

	private Object selectedItem;

	public CategoryComboBoxModel(CategoryModel categoryModel) {
		this.categoryList = categoryModel.getCategoryList();
	}

	public CategoryComboBoxModel(CategoryList categoryList) {
		this.categoryList = categoryList;
	}

	@Override
	public int getSize() {
		return categoryList.getCategoryCount();
	}

	@Override
	public Object getElementAt(int index) {
		return categoryList.getCategory(index);
	}

	@Override
	public void setSelectedItem(Object anItem) {
		selectedItem = anItem;
	}

	@Override
	public Object getSelectedItem() {
		return selectedItem;
	}

	@Override
	public void fireIntervalAdded(Object source, int index0, int index1) {
		super.fireIntervalAdded(source, index0, index1);
	}

	@Override
	public void fireIntervalRemoved(Object source, int index0, int index1) {
		super.fireIntervalRemoved(source, index0, index1);
	}
}
